#!/bin/bash
#leao:Sat Aug 24 10:35:49 AM CST 2024
sumCode() {
    local path=$1
    for val in `ls -a $path`;do
        if [ $val != '.' ] && [ $val != '..' ];then
            if [ -d "$path/$val" ];then
                sumCode "$path/$val"
            else
            case $val in
                *.c)
                    lines=$(cat "$path/$val" | wc -l)
                    ((sumlines += lines)) ;;
            esac
            fi
        fi
    done

}

path1=$1
echo "$path1"
if [ -z "$path1" ];then
    printf "错误：参数为空\n"
elif [ ! -d "$path1" ];then
    printf "错误：参数不是目录文件\n"
else
    sumCode $path1
fi
echo $sumlines

# sumCode(){
#     path=$1
#     for val in $( ls -a "$path" );do
#         if [ $val != '.' ] && [ $val != '..' ];then
#             if [ -d "$va"l ];then
#                 sumCode "$path/$val"
#             else
#                 case $val in
#                     *.c)
#                         lines=$( cat "$path/$val" | wc -l )
#                         ((sumLines+=lines)) ;;
#                 esac
#             fi
#         fi
#     done

# }
# sumCode $1
# echo $sumLines